<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义右键菜单</title>
    <style>
        *{
            margin: 0; padding: 0;
        }
        ul{
            position: absolute;
            list-style: none;
            background-color: #fff;
            border: 1px solid #ccc;
            display: none;
        }
        ul li{
            padding: 10px;
            width: 100px;
            border-bottom: 1px solid #ccc;
        }
        ul li:hover{
            background-color: #eee;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <ul id="select">
        <li>北京</li>
        <li>上海</li>
        <li>广州</li>
        <li>深圳</li>
    </ul>
    <script>
        var select = document.getElementById('select')

        document.oncontextmenu = function(e) {
            select.style.display = 'block';
            select.style.top = e.clientY + 'px'
            select.style.left = e.clientX + 'px'
            e.preventDefault();
        }

        for (let eml of select.querySelectorAll('li')) {
            eml.onclick = function() {
                alert(
                    this.innerHTML
                )
                select.style.display = 'none';
            }
        }

    </script>
</body>
</html>